home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 16 / 016.d81 / lk.conway's life < prev    next >
Text File  |  2022-08-26  |  2KB  |  101 lines

  1. 0010 //////////////////////////////////
  2. 0020 //                              //
  3. 0030 // conway's game of life -- by  //
  4. 0040 // joel ellis rea.              //
  5. 0050 //                              //
  6. 0060 //////////////////////////////////
  7. 0070 //
  8. 0080 //
  9. 0090 get'start'pattern
  10. 0100 g:=0
  11. 0110 repeat 
  12. 0120 compute'generation
  13. 0130 display'generation
  14. 0140 until peek(198)
  15. 0150 //
  16. 0160 proc get'start'pattern 
  17. 0170 dim char$ of 1
  18. 0180 print "", // clear screen, upper case.
  19. 0190 poke 53280,11
  20. 0200 poke 53280,11 // brdr dk grey
  21. 0210 poke 53281,12 // bkgnd md grey
  22. 0220 poke 646,1 // cursor white
  23. 0230 print "",tab(20),
  24. 0240 repeat 
  25. 0250 cursr:=peek(209)+256*peek(210)+peek(211)
  26. 0260 byte:=peek(cursr)
  27. 0270 poke cursr,87
  28. 0280 poke 198,0
  29. 0290 while not peek(198) do null
  30. 0300 char$:=key$
  31. 0310 case char$ of
  32. 0320 when "a","","A"
  33. 0330 print "",
  34. 0340 when "z","","Z"
  35. 0350 print "",
  36. 0360 when ",","","<"
  37. 0370 print "",
  38. 0380 when ".","",">"
  39. 0390 print "",
  40. 0400 when " "
  41. 0410 if byte=81 then
  42. 0420 poke cursr,32
  43. 0430 else 
  44. 0440 poke cursr,81
  45. 0450 endif 
  46. 0460 otherwise 
  47. 0470 null
  48. 0480 endcase 
  49. 0490 if char$<>" " then poke cursr,byte
  50. 0500 until char$=chr$(13)
  51. 0510 endproc get'start'pattern
  52. 0520 //
  53. 0530 proc compute'generation 
  54. 0540 blackout
  55. 0550 g:+1
  56. 0560 print "generation #",g
  57. 0570 for y#:=1 to 23 do
  58. 0580 for x#:=1 to 38 do
  59. 0590 if peek(1024+y#*40+x#)=81 then neighborize(x#,y#)
  60. 0600 endfor x#
  61. 0610 endfor y#
  62. 0620 endproc compute'generation
  63. 0630 //
  64. 0640 proc display'generation 
  65. 0650 for i#:=40 to 999 do
  66. 0660 case neighbors(i#) of
  67. 0670 when 0,1,4,5,6,7,8
  68. 0680 poke i#+1024,32
  69. 0690 when 2
  70. 0700 null
  71. 0710 when 3
  72. 0720 if peek(1024+i#)=32 then poke 1024+i#,81
  73. 0730 endcase 
  74. 0740 endfor i#
  75. 0750 endproc display'generation
  76. 0760 //
  77. 0770 proc blackout closed
  78. 0780 for i#:=40 to 999 do poke 55296+i#,0
  79. 0790 endproc blackout
  80. 0800 //
  81. 0810 proc neighborize(x,y) 
  82. 0820 if x>0 then increment(x-1,y)
  83. 0830 if x<39 then increment(x+1,y)
  84. 0840 if y>0 then increment(x,y-1)
  85. 0850 if y<24 then increment(x,y+1)
  86. 0860 if x>0 and y>0 then increment(x-1,y-1)
  87. 0870 if x>0 and y<24 then increment(x-1,y+1)
  88. 0880 if x<39 and y>0 then increment(x+1,y-1)
  89. 0890 if x<39 and y<24 then increment(x+1,y+1)
  90. 0900 endproc neighborize
  91. 0910 //
  92. 0920 func neighbors(i) closed
  93. 0930 return (peek(55296+i)) mod 16
  94. 0940 endfunc neighbors
  95. 0950 //
  96. 0960 proc increment(x,y) 
  97. 0970 l:=y*40+x
  98. 0980 poke 55296+l,neighbors(l)+1
  99. 0990 endproc increment
  100. 1000 //
  101.